package fhp.hlhj.giantfold.fragment;
import android.support.v4.app.Fragment;
/**
 * author: FHP
 * data: on 2017\12\12 0012 13:55
 * E-Mail: 103945089@qq.com
 */
public abstract class LazyFragment extends Fragment {
    protected boolean isVisible;
    /**
     * 在这里实现Fragment数据的缓加载.
     * @param isVisibleToUser
     */
    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if (getUserVisibleHint()) {
            isVisible = true;
            onVisible();
        } else {
            isVisible = false;
            onInvisible();
        }
    }
    protected void onVisible() {
        lazyLoad();
    }
    protected abstract void lazyLoad();
    protected void onInvisible() {}
}